import pytest
from tools.get_driver import GetDriver
from page.page_in import page_get_PageSkyeyeLogin
import page
from tools.read_yaml import read_yaml

class TestSkyeyeLogin:
    # 初始化
    def setup_class(self):
        # 1. 获取driver
        driver = GetDriver.get_web_driver(page.url_skyeye_vue)

        # 2. 通过同一入口获取PageSkyeyeLogin对象
        self.skyeye = page_get_PageSkyeyeLogin(driver)

    # 结束
    def teardown_class(self):
        # 调用关闭driver
        GetDriver.quit_web_driver()

    # 测试业务方法
    @pytest.mark.parametrize("username, password, expect", read_yaml("skyeye_login.yaml"))
    def test_skyeye_login(self, username , password, expect):
        # 调用登录业务方法
        self.skyeye.page_skyeye_login(username, password)
        # 断言操作
        # print("\n", "当前用户:",  self.skyeye.page_get_nickname())
        try:
            # 断言
            assert expect == self.skyeye.page_get_nickname()
        except Exception as e:
            # 输出断言信息
            print("错误原因：", e)
            # 截图
            self.skyeye.base_get_img()
            # 抛异常
            raise
